<h1 class="crayons-title mb-3">Organizations</h1>

<%= form_tag(admin_organizations_path, method: "get") do %>
  <div class="inline-flex">
    <%= search_field_tag(:search, params[:search], aria: { label: "Search" }, class: "crayons-textfield", autocomplete: "off") %>
    <%= submit_tag("Search", class: "crayons-btn ml-2") %>
  </div>
<% end %>

<%= paginate @organizations %>

<table class="crayons-table" width="100%">
  <thead>
    <tr>
      <th scope="col">Name</th>
      <th scope="col">ID</th>
      <th scope="col">Twitter</th>
      <th scope="col">GitHub</th>
      <th scope="col">URL</th>
    </tr>
  </thead>
  <tbody class="crayons-card">
    <% @organizations.each do |organization| %>
      <tr>
        <td><%= link_to "@#{organization.name}", admin_organization_path(organization.id) %></td>
        <td class="whitespace-nowrap"><%= organization.id %></td>
        <% if organization.twitter_username %>
          <td><%= link_to organization.twitter_username, "https://twitter.com/#{organization.twitter_username}" %></td>
        <% else %>
          <td>N/A</td>
        <% end %>
        <% if organization.github_username %>
          <td><%= link_to organization.github_username, "https://github.com/#{organization.github_username}" %></td>
        <% else %>
          <td>N/A</td>
        <% end %>
        <% if organization.url %>
          <td><%= link_to organization.url, organization.url %></td>
        <% else %>
          <td>N/A</td>
        <% end %>
      </tr>
    <% end %>
  </tbody>
</table>

<%= paginate @organizations %>
